package at.fhooe.stefanirndorfer.labeling;

import java.util.ArrayList;
import java.util.List;

public class Region_Manager {

	List<Region> regions;
	
	public Region_Manager(){
		regions = new ArrayList<Region>();
	}
	
	public synchronized void addRegion(Region r){
		regions.add(r);
	}
	
	public synchronized void removeRegion(Region r){
		for(int i = 0; i < regions.size(); i++){
			if(regions.get(i).equals(r)){
				Region reg = regions.get(i);
				reg.removeAllLeafs();
				regions.remove(i);
				break;
			}
		}
	}
	
	public synchronized void findAllBorderLeafs(){
	
		for(Region r : regions){
			r.findBorderLeafs();
		}
	
	}

	public void calculateGlobalConnectivityData() {
		calculateConnectivityData(regions);
		
	}

	private synchronized void calculateConnectivityData(List<Region> regs) {
		for(Region r: regs){
			r.calculateApertures();
		}
	}

	public List<Region> getRegions() {
		return regions;
	}
}
